import React, { Component } from 'react'
import { connect } from 'react-redux'
import  {add,asyncAdd} from "../reducers/numReducer"

export class Home extends Component<any,any> {
  render() {
    return (
      <div>Home

          <h3>全局的数据为{this.props.num}</h3>

          <button onClick={()=>{
              setTimeout(()=>{
                  this.props.add(2);
              },2000)
          }}>异步的修改</button>

          <button onClick={()=>{
              this.props.asyncAdd(3);
          }}>三秒改变</button>
      </div>
    )
  }
}

const mapStateToProps = (state:any) => ({
    num:state.numInfo.value
})

const mapDispatchToProps = {
    add,
    asyncAdd
}

export default connect(mapStateToProps, mapDispatchToProps)(Home)